package jdbcConnect;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class StudentMain_login {
    Connection conn=null;
    Statement stmt=null;
    Scanner s=new Scanner(System.in);

    public StudentMain_login(Connection conn, Statement stmt) {
        this.conn = conn;
        this.stmt = stmt;
    }
    public void Login(Statement stmt) throws SQLException {
        System.out.println("账号注册工作启动中...");
        System.out.print("请输入账号：");
        String loginName = s.nextLine();
        System.out.print("请输入密码：");
        String loginPwd = s.nextLine();
        System.out.println("请输入您的学生姓名:");
        String StudentName = s.nextLine();
        System.out.println("请输入您的年龄:");
        int age = s.nextInt();
        s.nextLine();
        System.out.println("请输入您的性别:");
        String sex = s.nextLine();
        //之前的loginName学号，loginPwd密码
        String insertsql = "insert into student values('" + loginName + "','" + StudentName + "','" + age + "','" + sex + "','" + loginPwd + "')";
        int i = stmt.executeUpdate(insertsql);
        if (i != 0) System.out.println("注册成功！");
//        String selectsql = "select * from student";
//        ResultSet rs = stmt.executeQuery(selectsql);
//        while (rs.next()) {
//            System.out.println(rs.getString(1) + "-" + rs.getString(2) + "-" + rs.getString(3) + "-" + rs.getString(4) + "-" + rs.getString(5));
//        }
    }
}
